#include <iostream>
#include <string>

using namespace std;


/*
浅拷贝 ： 如果类的内部没有指针 并不需要创建动态 内存空间
深拷贝 : 
*/

class My_class;

class My_class
{
private:
public:
    int *ptr;
    int val;

    My_class();

    My_class(const My_class & cl);

    ~My_class();
};

My_class::My_class(/* args */)
{
    ptr = new int(20);
    cout << "调用了构造" << endl;
}

My_class::My_class(const My_class & cl) // 拷贝构造
{
    ptr = new int(*cl.ptr);
    val = cl.val;
}

My_class::~My_class()
{
    if (ptr != nullptr)
    {
        delete ptr;
        ptr = NULL;
        cout << "调用了析构函数" << endl;
        return ;
    }

    cout << "重复调用" << endl;
}

int main(int argc, char const *argv[])
{
    My_class c1;
    *c1.ptr = 80;
    c1.val = 200;

    My_class c2 = c1;
    
    cout << c1.ptr << " " << *c1.ptr << " " << c1.val << endl;
    cout << c2.ptr << " " << *c2.ptr << " " << c2.val << endl;


    return 0;
}
